import { Type } from 'class-transformer';
import { IsNotEmpty, MaxLength, IsOptional, IsEnum } from 'class-validator';
import { RegionLevelTypes } from '../type/region.level.type';
import { RegionStatusTypes } from '../type/region.status.type';

// 新增dto验证
export class RegionInsertDto {
  @Type(() => String)
  @IsNotEmpty({ message: '代码不能为空' })
  @MaxLength(50, { message: '代码长度最长为 $constraint1 ' })
  code: string;

  @Type(() => String)
  @IsNotEmpty({ message: '名称不能为空' })
  @MaxLength(20, { message: '名称长度最长为 $constraint1 ' })
  name: string;

  @Type(() => Number)
  @IsNotEmpty({ message: '地区级别不能为空' })
  @IsEnum(RegionLevelTypes)
  level: number;

  @Type(() => String)
  @IsNotEmpty({ message: '城市代码不能为空' })
  @MaxLength(50, { message: '城市代码长度最长为 $constraint1 ' })
  city_code: string;

  @Type(() => String)
  @IsNotEmpty({ message: '经纬度不能为空' })
  @MaxLength(50, { message: '经纬度长度最长为 $constraint1 ' })
  center: string;

  @Type(() => Number)
  @IsNotEmpty({ message: '状态不能为空' })
  @IsEnum(RegionStatusTypes)
  status: number;

  @Type(() => Number)
  @IsOptional()
  @IsNotEmpty({ message: '父id不能为空' })
  parent_id: number;
}
